<template>
  <div class="sidebar">
    <div class="top-header">
      <img src="../../assets/imgs/home/avator.png" alt="">
    </div>

    <!-- 主要菜单项（前6个） -->
    <div class="main-menu">
      <div
        v-for="item in mainMenuItems"
        :key="item.id"
        class="menu-item"
        :class="{ active: activeItem === item.id }"
        @click="selectItem(item.id)"
      >
        <el-tooltip effect="dark" :content="item.name" placement="right">
          <div class="icon-container">
            <el-icon :size="24" :class="{ 'active-icon': activeItem === item.id }">
              <component :is="item.icon" />
            </el-icon>
          </div>
        </el-tooltip>
      </div>
    </div>

    <!-- 底部菜单项（后3个） -->
    <div class="bottom-menu">
      <div
        v-for="item in bottomMenuItems"
        :key="item.id"
        class="menu-item"
        :class="{ active: activeItem === item.id }"
        @click="selectItem(item.id)"
      >
        <el-tooltip effect="dark" :content="item.name" placement="right">
          <div class="icon-container">
            <el-icon :size="24" :class="{ 'active-icon': activeItem === item.id }">
              <component :is="item.icon" />
            </el-icon>
          </div>
        </el-tooltip>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import {
  ChatDotRound,
  User,
  Star,
  Folder,
  Picture,
  Search,
  Grid,
  Iphone,
  Setting
} from '@element-plus/icons-vue'

const emit = defineEmits(['change-view'])
const activeItem = ref('chat')

const allMenuItems = [
  { id: 'chat', name: '聊天', icon: ChatDotRound },
  { id: 'contacts', name: '联系人', icon: User },
  { id: 'discover', name: '收藏', icon: Star },
  { id: 'folder', name: '文件夹', icon: Folder },
  { id: 'friend', name: '朋友圈', icon: Picture },
  { id: 'look', name: '看一看', icon: Search },
  { id: 'uniapp', name: '小程序面板', icon: Grid },
  { id: 'phone', name: '手机', icon: Iphone },
  { id: 'setting', name: '设置', icon: Setting },
]

// 分割菜单项
const mainMenuItems = computed(() => allMenuItems.slice(0, 6))
const bottomMenuItems = computed(() => allMenuItems.slice(6))

const selectItem = (itemId) => {
  activeItem.value = itemId
  emit('change-view', itemId)
}
</script>

<style lang="scss" scoped>
.sidebar {
   width: 100%;
  height: 100vh; // 确保占满整个视口高度
  background-color: rgb(46, 46, 46);
  display: flex;
  flex-direction: column;
  overflow: hidden; // 隐藏溢出内容，防止滚动条出现

  .top-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px 0;

    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      object-fit: cover;
    }
  }

  .main-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-top: 10px;
  }

  .bottom-menu {
    margin-bottom: 20px;
  }

  .menu-item {
    width: 100%;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin-bottom: 10px;
    border-radius: 4px;
    transition: all 0.3s;

    &:hover {
      background-color: rgba(255, 255, 255, 0.1);
    }

    .icon-container {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 40px;
      height: 40px;

      .el-icon {
        color: #a8a8a8;
        transition: color 0.3s;

        &.active-icon {
          color: rgb(7, 193, 96);
        }
      }
    }
  }
}
</style>
